#include<stdio.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<errno.h>
#include<stdlib.h>
#include<string.h>
char* const g_argev1[]={(char* const)"/usr/bin/ls",(char* const)"-a",(char* const)"-l",NULL};
char* const g_argev2[]={(char* const)"ls",(char* const)"-a",(char* const)"-l",NULL};
char* const env[]={(char* const)"HPP=128",(char* const)"GHH=29",(char* const)"p=..",NULL};
int main()
{
    pid_t id=fork();
    if(id==0)
    {
        //execl("/usr/bin/ls","ls","-l","-a",NULL);
        //execv(g_argev1[0],g_argev1); 
        //execlp("ls","-ln","-a",NULL);
        //execvp(g_argev2[0],g_argev2);
        
        
        //execle("./code","ls","-l","-a",NULL,env);
        //execve(g_argev1[0],g_argev2,env);
        
        exit(1);
    }
    int status;
    pid_t p=waitpid(id,&status,0);
    if(p>0)
    {
        if(WIFEXITED(status))
        {
            printf("exit code:%d,exit signal:%d\n",WEXITSTATUS(status),status&0x7);
        }
        else 
        {
            printf("程序执行异常\n");
        }
    }
    else
    {
        printf("waitpid fail:%s",strerror(errno));

    }
    return 0;
}
